home *** CD-ROM | disk | FTP | other *** search
- class Enemy extends MovieClipHolder implements Steppable
- {
- var mc;
- var health;
- var targetCoords;
- var xspeed;
- var yspeed;
- var tm;
- var dm;
- static var SCORE = 100;
- static var SPEED = 5;
- static var WAIT_TIME = 60;
- static var ENEMY_TYPE = "enemy1";
- static var MAX_HEALTH = 2;
- static var COLOR = 16776960;
- static var SHAPE_FLAG = false;
- static var enemies = new ObjectList();
- var timer = 0;
- var missileCheckNumber = 0;
- function Enemy(x, y)
- {
- super(_root.attachMovie(this.getEnemyType(),this.getEnemyType() + _root.getNextHighestDepth(),_root.getNextHighestDepth()),this.getColor(),true);
- this.mc._x = x;
- this.mc._y = y;
- this.assignNewTarget();
- this.createTrailManager();
- this.createDebrisManager();
- this.health = this.getMaxHealth();
- Stepper.add(this);
- Enemy.add(this);
- var _loc4_ = Math.atan2(this.targetCoords.y - this.mc._y,this.targetCoords.x - this.mc._x);
- this.xspeed = this.getSpeed() * Math.cos(_loc4_);
- this.yspeed = this.getSpeed() * Math.sin(_loc4_);
- this.mc._rotation = CustomMath.radToDeg(_loc4_);
- }
- function getScore()
- {
- return Enemy.SCORE;
- }
- function getSpeed()
- {
- return Enemy.SPEED;
- }
- function getEnemyType()
- {
- return Enemy.ENEMY_TYPE;
- }
- function getWaitTime()
- {
- return Enemy.WAIT_TIME;
- }
- function getMaxHealth()
- {
- return Enemy.MAX_HEALTH;
- }
- function getColor()
- {
- return Enemy.COLOR;
- }
- function getShapeFlag()
- {
- return Enemy.SHAPE_FLAG;
- }
- static function add(m)
- {
- Enemy.enemies.add(m);
- }
- static function remove(m)
- {
- Enemy.enemies.remove(m);
- }
- function step()
- {
- if(this.checkProximity())
- {
- this.shootIfAble();
- this.tm.die();
- delete this.tm;
- }
- else
- {
- this.move();
- }
- this.checkHit();
- }
- function createDebrisManager()
- {
- this.dm = new DebrisManager(this.getColor(),6);
- }
- function createTrailManager()
- {
- if(_root.effects >= 2)
- {
- this.tm = new TrailManager(this.mc,this.mc.exhaust1,1,16566798);
- }
- else
- {
- this.tm = new TrailManager(this.mc,this.mc.exhaust1,1);
- }
- }
- function checkProximity()
- {
- return Math.abs(this.mc._x - this.targetCoords.x) < 10 && Math.abs(this.mc._y - this.targetCoords.y) < 10;
- }
- function move()
- {
- this.mc._x += this.xspeed;
- this.mc._y += this.yspeed;
- this.tm.makeTrail();
- }
- function getWeaponsPoints()
- {
- var _loc2_ = new flash.geom.Point(this.mc.weapon1._x,this.mc.weapon1._y);
- this.mc.localToGlobal(_loc2_);
- return new Array(_loc2_);
- }
- function shootIfAble()
- {
- this.rotateToPlayer();
- if(this.timer > this.getWaitTime())
- {
- var _loc4_ = this.getWeaponsPoints();
- var _loc2_ = 0;
- while(_loc2_ < _loc4_.length)
- {
- var _loc3_ = _loc4_[_loc2_];
- this.createNewMissile(_loc3_.x,_loc3_.y);
- _loc2_ = _loc2_ + 1;
- }
- this.timer = 0;
- }
- this.timer = this.timer + 1;
- }
- function assignNewTarget()
- {
- this.targetCoords = new flash.geom.Point(CustomMath.randomRange(100,Stage.width - 100),CustomMath.randomRange(100,Stage.height - 100));
- }
- function createNewMissile(x, y)
- {
- new Missile(x,y);
- }
- function rotateToPlayer()
- {
- var _loc3_ = Math.atan2(_root.player.getMovie()._y - this.mc._y,_root.player.getMovie()._x - this.mc._x);
- this.mc._rotation = CustomMath.radToDeg(_loc3_);
- }
- function checkHit()
- {
- var _loc3_ = this.missileCheckNumber;
- while(_loc3_ < Missile.missiles.getLength())
- {
- var _loc2_ = Missile.missiles["get"](_loc3_);
- if(_loc2_.hit(this.mc,this.getShapeFlag()))
- {
- this.health -= _loc2_.getDamage();
- _loc2_.die();
- }
- _loc3_ += 2;
- }
- if(this.health <= 0)
- {
- this.die();
- }
- if(this.missileCheckNumber == 0)
- {
- this.missileCheckNumber = 1;
- }
- else
- {
- this.missileCheckNumber = 0;
- }
- }
- function die()
- {
- if(this.health <= 0)
- {
- ScoreManager.addScore(this.getScore());
- ScoreManager.incrementMultiplier();
- }
- this.tm.die();
- this.dm.createDebrisField(this.mc._x,this.mc._y);
- Stepper.remove(this);
- Enemy.remove(this);
- this.mc.blendMode = "normal";
- var _loc3_ = new Array();
- _loc3_.push(new flash.filters.GlowFilter(this.getColor(),100,15,15,1.5,1));
- this.mc.filters = _loc3_;
- this.mc.swapDepths(_root.getNextHighetDepth());
- this.mc.gotoAndPlay("death");
- }
- }
-